﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;

namespace YasharEl.Infrastructure.ApplicationModel.Bootstrap.Extensibility
{
    /// <summary>
    /// Extension point for bootstrapper.
    /// </summary>
    /// <typeparam name="TExtension">The type of the extension.</typeparam>
    [ContractClass(typeof(BootstrappingExtensionPointContract<>))]
    public interface IBootstrappingExtensionPoint<TExtension> where TExtension : IBootstrappingExtension
    {
        /// <summary>
        /// Adds the extension to the bootstrapping mechanism. 
        /// The extensions are executed in the order which they were added.
        /// </summary>
        /// <param name="extension">The extension to be added.</param>
        void AddExtension(TExtension extension);
    }

    [ContractClassFor(typeof(IBootstrappingExtensionPoint<>))]
    internal abstract class BootstrappingExtensionPointContract<TExtension> : IBootstrappingExtensionPoint<TExtension>
        where TExtension : IBootstrappingExtension
    {
        public void AddExtension(TExtension extension)
        {
            Contract.Requires<ArgumentNullException>(extension != null, "extension could not be null.");
        }
    }
}
